#include <bits/stdc++.h>

using i64 = long long;

void out(auto &a) {
    for (auto &v : a) {
        for (auto x : v) {
            std::cout << x << " ";
        }
        std::cout << std::endl;
    }
}

// 行列式求值
{
    int n, p;
    std::cin >> n >> p;

    std::vector a(n, std::vector<i64>(n));
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            std::cin >> a[i][j];
        }
    }

    bool flag = false;
    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n; ++j) {
            while (a[i][i] != 0) {
                int t = a[j][i] / a[i][i];
                for (int k = i; k < n; ++k) {
                    a[j][k] = (a[j][k] - t * a[i][k]) % p;
                    a[j][k] = (a[j][k] + p) % p;
                }
                std::swap(a[i], a[j]);
                flag = !flag;
            }
            std::swap(a[i], a[j]);
            flag = !flag;
        }
    }

    // out(a);

    i64 ans = flag ? -1 : 1;
    for (int i = 0; i < n; ++i) {
        ans = (ans * a[i][i] + p) % p;
    }
    std::cout << ans;
}

// 矩阵求逆
{
    int n;
    std::cin >> n;

    std::vector a(n, std::vector<i64>(n * 2));
    for (int i = 0; i < n; ++i) {
        a[i][i + n] = 1;
        for (int j = 0; j < n; ++j) {
            std::cin >> a[i][j];
        }
    }

    // out(a);

    bool flag = true;
    for (int i = 0; i < n; ++i) {
        int k = i;
        for (int j = i; j < n; ++j) {
            if (std::abs(a[k][i]) < std::abs(a[j][i])) {
                k = j;
            }
        }
        if (std::abs(a[k][i]) == 0) {
            flag = false;
            break;
        }

        std::swap(a[k], a[i]);

        auto t = pow(a[i][i], MOD - 2, MOD);
        for (int j = n * 2; j >= i; --j) {
            // a[i][j] /= a[i][i];
            a[i][j] = (a[i][j] * t) % MOD;
        }
        for (int j = 0; j < n; ++j) {
            if (i != j) {
                auto d = -a[j][i];
                for (int t = i; t < n * 2; ++t) {
                    a[j][t] = (a[j][t] + d * a[i][t]) % MOD;
                    a[j][t] = (a[j][t] + MOD) % MOD;
                }
            }
        }
    }

    // out(a);

    // std::cout << std::fixed << std::setprecision(2);

    if (!flag) {
        std::cout << "No Solution";
    } else {
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < n; ++j) {
                std::cout << a[i][j + n] << " \n"[j == n - 1];
            }
        }
    }
}
